package com.example.zxmzy.xl;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.fragment.app.Fragment;

import com.example.zxmzy.R;
import com.example.zxmzy.activity.DetailActivity;
import com.example.zxmzy.pp.SpPp;
import com.example.zxmzy.entity.Sp;
import com.example.zxmzy.sqlite.DBSp;

import java.util.List;


public class MainXl extends Fragment {

    private ListView lvStuff;
    private List<Sp> stuffList;
    private SpPp adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.xl_main, container, false);
        bindView(v);
        initView();
        return v;
    }

    private void bindView(View v) {
        lvStuff = v.findViewById(R.id.lv_stuff);
    }

    private void initView() {
        stuffList = DBSp.getAll();
        adapter = new SpPp(getContext(), R.layout.iq_sp, stuffList);
        lvStuff.setAdapter(adapter);
        lvStuff.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent();
                intent.putExtra("id", (stuffList.get(i)).getId());
                intent.setClass(getContext(), DetailActivity.class);
                startActivity(intent);
            }
        });
    }


}